package day12;

import java.util.Arrays;

//此类是用于验证String类型常见API的测试DEMO
public class TestString {
    public static void main(String[] args) {
        String s1 = "abc";
        char [] value = {'a' , 'b' , 'c'};
        String s2 = new String(value);  //将CHAR类型转化为String

        //2测试String的常用API
//        System.out.println(s1.hashCode());
//        System.out.println(s2.hashCode());
//
//        System.out.println(s1.equals(s2));
//
//        System.out.println(s1.toString());
//        System.out.println(s2.toString());
        System.out.println(s1.length());   //统计s1长度
        System.out.println(s1.toUpperCase());   //将字符串的内容转为大写
        System.out.println(s1.toLowerCase());    //将字符串转换为小写
        System.out.println(s1.startsWith("a"));  //判断字符串首字母是否为a
        System.out.println(s1.endsWith("a"));
        System.out.println(s2.length());
        System.out.println(s1.charAt(0));   //输出下标为0的元素，其实就是输出第一个字符
        System.out.println("---------");
        String s3 = "abcddbba";
        System.out.println(s3.indexOf("b"));   //判断第一个b元素下表
        System.out.println(s3.lastIndexOf("b"));      //判断s3最后一个b元素下标
        System.out.println(s2.concat("haha"));    //在变量s2之后拼接haha,并且不改变原来s2
        System.out.println(s2);
        String s4 = s2.concat("haha");
        System.out.println(s4);

        String s5= "abcdefgfefc";
        System.out.println(Arrays.toString(s5.split("f")));

        String s6 = "abcdefg";
        System.out.println(s6.substring(3));  //从下标为3的位置到最后
        System.out.println(s6.substring(3,6));    //输出下标为3-6的字符含头去尾
        System.out.println(s6.substring(2,5));     //下标a为0 b为1
    }
}
